<div class="center">
	<div class="home">
        <div class="home_left">
            <?php echo $this->partial('member/menu.phtml',array('uCount' => $this->uCount,'menuId'=>$this->menuId,'user'=>$this->user,'account'=>$this->account)); ?>
        </div>
        <div class="home_right">
        
        
            <div class="shezhi">
            	<h1><i></i>个人设置</h1>
            </div>
            
            <div class="shezhinav">
                <ul>
                    <li><a href="/member/profile"><i class="shezhi1"></i>个人信息设置</a></li>
                    
                    <li><a href="/member/password"><i class="shezhi3"></i>修改登录密码</a></li>
                    
                    <li class="shezhion"><a href="/member/email"><i class="shezhi3"></i>修改邮箱</a></li>
                </ul>
            </div>
        <form id="form1" method="post">
    	
      
    		<div class="mimatishi">
            	<h1>为了更好的保护您的帐号安全，避免您的损失，建议您更换邮箱时：</h1>
                <ul>
                	<li>1. 先将电脑全面杀毒，再设置新密码；</li>
                	<li>2. 验证安全邮箱。</li>
                </ul>
            </div>
            <div class="mimatable">
            	<table>                	
                	<tr>
                    	<td class="mz"><span>*</span>新邮箱：</td>
                        <td>
                        	<input type="text" id="email" name="email" /><p id="div_password" style="display:none;"><i></i>新邮箱不能为空</p>
                        </td>
                    </tr>
                	<tr>
                    	<td class="mz"><span>*</span>确认新邮箱：</td>
                        <td>
                        	<input type="text" id="email2" name="email2" /><p id="div_password2" style="display:none;"><i></i>确认新邮箱不能为空</p><p id="div_password_not_right" style="display:none;"><i></i>输入的两次邮箱不一致</p>
                        </td>
                    </tr>
                </table>
                
                <div class="mimatijiao">
                	<a onclick="javascript:formsubmit()"><span>提交修改</span></a>
                </div>
                
            </div>

        </form>


        </div>
        

    </div>
</div>

<script language="javascript">
$('#email').blur(function(){
   var email = $("#email").val(); 
   var reg = /^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/;
   if(!reg.test(email)){
       $('#div_password').html("<i></i>输入的邮箱不合法！");
       $("#div_password").show();
       $("#email").focus();
   }else{
        $.post(
            '/member/checkemail',
            {'email':email},
            function (data){
                if(data === 1){
                    $('#div_password').html("<i></i>该邮箱已经被别的用户占用！");
                    $("#div_password").show();
                    $("#email").focus();
                }else if(data === 0){
                    $("#div_password").hide();
                }
            }
        );
   }
});    
    
    
function check_form(){
        var email = $("#email").val();
        var reg = /^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/; 
        if(email === ""){
                $("#div_password").show();
                $("#email").focus();
                return false;
        }else if(!reg.test(email)){
                $('#div_password').html("<i></i>输入的邮箱不合法！");
                $("#div_password").show();
                $("#email").focus();
                return false;
        }else{
               $("#div_password").hide();
        }
        var email2 = $("#email2").val();
        if(email2 === ""){
                $("#div_password2").show();
                $("#email2").focus();
                return false;
        }else{
                $("#div_password2").hide();
        }
        if(email !== email2){
                $("#div_password_not_right").show();
                $("#email2").focus();
                return false;
        }else{
                $("#div_password_not_right").hide();
        }
        return true;
}

function formsubmit(){		
        if(check_form()){
            var email = $('#email').val();
            var email2 = $('#email2').val();
            $.post(
                '/member/email',
                {'email':email,'email2':email2},
                function (data){
                    if(data.type === 1){
                        $('.mimatijiao').html("<font size='4' color='green'>更新邮箱成功！系统正在为您发送验证邮件……<br/>　&nbsp;&nbsp;请您稍等片刻…………</font>");
                        $.post(
                            '/member/activation',
                            {'uid':data.uid}
                        );
                        window.location.href = "/member/home";
                    }else{
                        $('.mimatijiao').html("<font size='4' color='red'>很抱歉，您修改邮箱失败！</font>");
                    }
                }
            );
        }
}
</script>
